<template>
  <link rel="stylesheet" href="/assets/css/team.css" />

  <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
    <van-list
      class="list"
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="avatar">
          <img :src="item.avatar_text" alt="" />
        </div>
        <div class="info">
          <div class="name">昵称：{{ item.nickname }}</div>
          <div class="type">电话号码：{{ item.mobile }}</div>
          <div class="time">注册时间：{{ item.createtime_text }}</div>
        </div>
      </div>
    </van-list>
  </van-pull-refresh>
</template>
<script setup>
import { getCurrentInstance } from "vue";

const { proxy } = getCurrentInstance();

const list = ref([]);
const count = ref(0);
const loading = ref(false);
const finished = ref(false);
const refreshing = ref(false);
const business = proxy.$business.value;

//上拉
const onLoad = () => {
  setTimeout(async () => {
    loading.value = true;
    //请求成功后清除旧的数据,并取消刷新状态
    if (refreshing.value) {
      list.value = [];
      refreshing.value = false;
    }
    var result = await proxy.$POST({
      url: "business/team",
      params: { id: business.id },
    });

   
    if (result.code == 1) {
      count.value = result.data.count;
      list.value = result.data.list;
      loading.value = false;
    }

    console.log(list.value)
    if (list.value.length >= count.value) {
      finished.value = true;
    }
  }, 500);
};

const onRefresh = () => {
  // 清空列表数据
  finished.value = true;

  // 重新加载数据
  onLoad();
};
</script>